package com.fch.sdlibrary;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.Toast;

import com.fch.sdlibrary.entity.Book;
import com.fch.sdlibrary.util.BookAdapter;

import java.util.ArrayList;
import java.util.List;

public class IndexActivity extends AppCompatActivity{

    private ListView listView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_index);

        listView = findViewById(R.id.my_list);

        List<Book> mData = new ArrayList<>();
        Book book = new Book();
        book.setBookId(1);
        book.setBookAuthor("");
        book.setBookImg("img0.jpg");
        book.setBookClassName("");
        book.setBookQuantity(1);
        book.setBookIsbn("");
        mData.add(book);

        BookAdapter adapter = new BookAdapter(mData, this.getLayoutInflater());
        //将布局添加到ListView中
        listView.setAdapter(adapter);
        listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
                Book book = (Book) listView.getAdapter().getItem(i);
                Toast.makeText(IndexActivity.this, book.toString(), Toast.LENGTH_SHORT).show();
            }
        });
    }

}
